home *** CD-ROM | disk | FTP | other *** search
/ PC Open 102 / PC Open 102 CD 1.bin / CD1 / INTERNET / EMAIL / pop file / setup.exe / $_1_ / URI.pm < prev    next >
Encoding:
Perl POD Document  |  2004-02-03  |  27.9 KB  |  918 lines

  1. package URI;
  2.  
  3. use strict;
  4. use vars qw($VERSION);
  5. $VERSION = "1.27"; # $Date: 2003/10/06 10:38:31 $
  6.  
  7. use vars qw($ABS_REMOTE_LEADING_DOTS $ABS_ALLOW_RELATIVE_SCHEME);
  8.  
  9. my %implements;  # mapping from scheme to implementor class
  10.  
  11. # Some "official" character classes
  12.  
  13. use vars qw($reserved $mark $unreserved $uric $scheme_re);
  14. $reserved   = q(;/?:@&=+$,[]);
  15. $mark       = q(-_.!~*'());                                    #'; emacs
  16. $unreserved = "A-Za-z0-9\Q$mark\E";
  17. $uric       = quotemeta($reserved) . $unreserved . "%";
  18.  
  19. $scheme_re  = '[a-zA-Z][a-zA-Z0-9.+\-]*';
  20.  
  21. use Carp ();
  22. use URI::Escape ();
  23.  
  24. use overload ('""'     => sub { ${$_[0]} },
  25.           '=='     => sub { overload::StrVal($_[0]) eq
  26.                                 overload::StrVal($_[1])
  27.                               },
  28.               fallback => 1,
  29.              );
  30.  
  31. sub new
  32. {
  33.     my($class, $uri, $scheme) = @_;
  34.  
  35.     $uri = defined ($uri) ? "$uri" : "";   # stringify
  36.     # Get rid of potential wrapping
  37.     $uri =~ s/^<(?:URL:)?(.*)>$/$1/;  # 
  38.     $uri =~ s/^"(.*)"$/$1/;
  39.     $uri =~ s/^\s+//;
  40.     $uri =~ s/\s+$//;
  41.  
  42.     my $impclass;
  43.     if ($uri =~ m/^($scheme_re):/so) {
  44.     $scheme = $1;
  45.     }
  46.     else {
  47.     if (($impclass = ref($scheme))) {
  48.         $scheme = $scheme->scheme;
  49.     }
  50.     elsif ($scheme && $scheme =~ m/^($scheme_re)(?::|$)/o) {
  51.         $scheme = $1;
  52.         }
  53.     }
  54.     $impclass ||= implementor($scheme) ||
  55.     do {
  56.         require URI::_foreign;
  57.         $impclass = 'URI::_foreign';
  58.     };
  59.  
  60.     return $impclass->_init($uri, $scheme);
  61. }
  62.  
  63.  
  64. sub new_abs
  65. {
  66.     my($class, $uri, $base) = @_;
  67.     $uri = $class->new($uri, $base);
  68.     $uri->abs($base);
  69. }
  70.  
  71.  
  72. sub _init
  73. {
  74.     my $class = shift;
  75.     my($str, $scheme) = @_;
  76.     $str =~ s/([^$uric\#])/$URI::Escape::escapes{$1}/go;
  77.     $str = "$scheme:$str" unless $str =~ /^$scheme_re:/o ||
  78.                                  $class->_no_scheme_ok;
  79.     my $self = bless \$str, $class;
  80.     $self;
  81. }
  82.  
  83.  
  84. sub implementor
  85. {
  86.     my($scheme, $impclass) = @_;
  87.     if (!$scheme || $scheme !~ /\A$scheme_re\z/o) {
  88.     require URI::_generic;
  89.     return "URI::_generic";
  90.     }
  91.  
  92.     $scheme = lc($scheme);
  93.  
  94.     if ($impclass) {
  95.     # Set the implementor class for a given scheme
  96.         my $old = $implements{$scheme};
  97.         $impclass->_init_implementor($scheme);
  98.         $implements{$scheme} = $impclass;
  99.         return $old;
  100.     }
  101.  
  102.     my $ic = $implements{$scheme};
  103.     return $ic if $ic;
  104.  
  105.     # scheme not yet known, look for internal or
  106.     # preloaded (with 'use') implementation
  107.     $ic = "URI::$scheme";  # default location
  108.  
  109.     # turn scheme into a valid perl identifier by a simple tranformation...
  110.     $ic =~ s/\+/_P/g;
  111.     $ic =~ s/\./_O/g;
  112.     $ic =~ s/\-/_/g;
  113.  
  114.     no strict 'refs';
  115.     # check we actually have one for the scheme:
  116.     unless (@{"${ic}::ISA"}) {
  117.         # Try to load it
  118.         eval "require $ic";
  119.         die $@ if $@ && $@ !~ /Can\'t locate.*in \@INC/;
  120.         return unless @{"${ic}::ISA"};
  121.     }
  122.  
  123.     $ic->_init_implementor($scheme);
  124.     $implements{$scheme} = $ic;
  125.     $ic;
  126. }
  127.  
  128.  
  129. sub _init_implementor
  130. {
  131.     my($class, $scheme) = @_;
  132.     # Remember that one implementor class may actually
  133.     # serve to implement several URI schemes.
  134. }
  135.  
  136.  
  137. sub clone
  138. {
  139.     my $self = shift;
  140.     my $other = $$self;
  141.     bless \$other, ref $self;
  142. }
  143.  
  144.  
  145. sub _no_scheme_ok { 0 }
  146.  
  147. sub _scheme
  148. {
  149.     my $self = shift;
  150.  
  151.     unless (@_) {
  152.     return unless $$self =~ /^($scheme_re):/o;
  153.     return $1;
  154.     }
  155.  
  156.     my $old;
  157.     my $new = shift;
  158.     if (defined($new) && length($new)) {
  159.     Carp::croak("Bad scheme '$new'") unless $new =~ /^$scheme_re$/o;
  160.     $old = $1 if $$self =~ s/^($scheme_re)://o;
  161.     my $newself = URI->new("$new:$$self");
  162.     $$self = $$newself; 
  163.     bless $self, ref($newself);
  164.     }
  165.     else {
  166.     if ($self->_no_scheme_ok) {
  167.         $old = $1 if $$self =~ s/^($scheme_re)://o;
  168.         Carp::carp("Oops, opaque part now look like scheme")
  169.         if $^W && $$self =~ m/^$scheme_re:/o
  170.     }
  171.     else {
  172.         $old = $1 if $$self =~ m/^($scheme_re):/o;
  173.     }
  174.     }
  175.  
  176.     return $old;
  177. }
  178.  
  179. sub scheme
  180. {
  181.     my $scheme = shift->_scheme(@_);
  182.     return unless defined $scheme;
  183.     lc($scheme);
  184. }
  185.  
  186.  
  187. sub opaque
  188. {
  189.     my $self = shift;
  190.  
  191.     unless (@_) {
  192.     $$self =~ /^(?:$scheme_re:)?([^\#]*)/o or die;
  193.     return $1;
  194.     }
  195.  
  196.     $$self =~ /^($scheme_re:)?    # optional scheme
  197.             ([^\#]*)          # opaque
  198.                 (\#.*)?           # optional fragment
  199.               $/sx or die;
  200.  
  201.     my $old_scheme = $1;
  202.     my $old_opaque = $2;
  203.     my $old_frag   = $3;
  204.  
  205.     my $new_opaque = shift;
  206.     $new_opaque = "" unless defined $new_opaque;
  207.     $new_opaque =~ s/([^$uric])/$URI::Escape::escapes{$1}/go;
  208.  
  209.     $$self = defined($old_scheme) ? $old_scheme : "";
  210.     $$self .= $new_opaque;
  211.     $$self .= $old_frag if defined $old_frag;
  212.  
  213.     $old_opaque;
  214. }
  215.  
  216. *path = \&opaque;  # alias
  217.  
  218.  
  219. sub fragment
  220. {
  221.     my $self = shift;
  222.     unless (@_) {
  223.     return unless $$self =~ /\#(.*)/s;
  224.     return $1;
  225.     }
  226.  
  227.     my $old;
  228.     $old = $1 if $$self =~ s/\#(.*)//s;
  229.  
  230.     my $new_frag = shift;
  231.     if (defined $new_frag) {
  232.     $new_frag =~ s/([^$uric])/$URI::Escape::escapes{$1}/go;
  233.     $$self .= "#$new_frag";
  234.     }
  235.     $old;
  236. }
  237.  
  238.  
  239. sub as_string
  240. {
  241.     my $self = shift;
  242.     $$self;
  243. }
  244.  
  245.  
  246. sub canonical
  247. {
  248.     my $self = shift;
  249.  
  250.     # Make sure scheme is lowercased
  251.     my $scheme = $self->_scheme || "";
  252.     my $uc_scheme = $scheme =~ /[A-Z]/;
  253.     my $lc_esc    = $$self =~ /%(?:[a-f][a-fA-F0-9]|[A-F0-9][a-f])/;
  254.     if ($uc_scheme || $lc_esc) {
  255.     my $other = $self->clone;
  256.     $other->_scheme(lc $scheme) if $uc_scheme;
  257.     $$other =~ s/(%(?:[a-f][a-fA-F0-9]|[A-F0-9][a-f]))/uc($1)/ge
  258.         if $lc_esc;
  259.     return $other;
  260.     }
  261.     $self;
  262. }
  263.  
  264. # Compare two URIs, subclasses will provide a more correct implementation
  265. sub eq {
  266.     my($self, $other) = @_;
  267.     $self  = URI->new($self, $other) unless ref $self;
  268.     $other = URI->new($other, $self) unless ref $other;
  269.     ref($self) eq ref($other) &&                # same class
  270.     $self->canonical->as_string eq $other->canonical->as_string;
  271. }
  272.  
  273. # generic-URI transformation methods
  274. sub abs { $_[0]; }
  275. sub rel { $_[0]; }
  276.  
  277. # help out Storable
  278. sub STORABLE_freeze {
  279.        my($self, $cloning) = @_;
  280.        return $$self;
  281. }
  282.  
  283. sub STORABLE_thaw {
  284.        my($self, $cloning, $str) = @_;
  285.        $$self = $str;
  286. }
  287.  
  288. 1;
  289.  
  290. __END__
  291.  
  292. =head1 NAME
  293.  
  294. URI - Uniform Resource Identifiers (absolute and relative)
  295.  
  296. =head1 SYNOPSIS
  297.  
  298.  $u1 = URI->new("http://www.perl.com");
  299.  $u2 = URI->new("foo", "http");
  300.  $u3 = $u2->abs($u1);
  301.  $u4 = $u3->clone;
  302.  $u5 = URI->new("HTTP://WWW.perl.com:80")->canonical;
  303.  
  304.  $str = $u->as_string;
  305.  $str = "$u";
  306.  
  307.  $scheme = $u->scheme;
  308.  $opaque = $u->opaque;
  309.  $path   = $u->path;
  310.  $frag   = $u->fragment;
  311.  
  312.  $u->scheme("ftp");
  313.  $u->host("ftp.perl.com");
  314.  $u->path("cpan/");
  315.  
  316. =head1 DESCRIPTION
  317.  
  318. This module implements the C<URI> class.  Objects of this class
  319. represent "Uniform Resource Identifier references" as specified in RFC
  320. 2396 (and updated by RFC 2732).
  321.  
  322. A Uniform Resource Identifier is a compact string of characters for
  323. identifying an abstract or physical resource.  A Uniform Resource
  324. Identifier can be further classified either a Uniform Resource Locator
  325. (URL) or a Uniform Resource Name (URN).  The distinction between URL
  326. and URN does not matter to the C<URI> class interface. A
  327. "URI-reference" is a URI that may have additional information attached
  328. in the form of a fragment identifier.
  329.  
  330. An absolute URI reference consists of three parts.  A I<scheme>, a
  331. I<scheme specific part> and a I<fragment> identifier.  A subset of URI
  332. references share a common syntax for hierarchical namespaces.  For
  333. these the scheme specific part is further broken down into
  334. I<authority>, I<path> and I<query> components.  These URI can also
  335. take the form of relative URI references, where the scheme (and
  336. usually also the authority) component is missing, but implied by the
  337. context of the URI reference.  The three forms of URI reference
  338. syntax are summarized as follows:
  339.  
  340.   <scheme>:<scheme-specific-part>#<fragment>
  341.   <scheme>://<authority><path>?<query>#<fragment>
  342.   <path>?<query>#<fragment>
  343.  
  344. The components that a URI reference can be divided into depend on the
  345. I<scheme>.  The C<URI> class provides methods to get and set the
  346. individual components.  The methods available for a specific
  347. C<URI> object depend on the scheme.
  348.  
  349. =head1 CONSTRUCTORS
  350.  
  351. The following methods construct new C<URI> objects:
  352.  
  353. =over 4
  354.  
  355. =item $uri = URI->new( $str, [$scheme] )
  356.  
  357. This class method constructs a new URI object.  The string
  358. representation of a URI is given as argument together with an optional
  359. scheme specification.  Common URI wrappers like "" and <>, as well as
  360. leading and trailing white space, are automatically removed from
  361. the $str argument before it is processed further.
  362.  
  363. The constructor determines the scheme, maps this to an appropriate
  364. URI subclass, constructs a new object of that class and returns it.
  365.  
  366. The $scheme argument is only used when $str is a
  367. relative URI.  It can either be a simple string that
  368. denotes the scheme, a string containing an absolute URI reference or
  369. an absolute C<URI> object.  If no $scheme is specified for a relative
  370. URI $str, then $str is simply treated as a generic URI (no scheme
  371. specific methods available).
  372.  
  373. The set of characters available for building URI references is
  374. restricted (see L<URI::Escape>).  Characters outside this set are
  375. automatically escaped by the URI constructor.
  376.  
  377. =item $uri = URI->new_abs( $str, $base_uri )
  378.  
  379. This constructs a new absolute URI object.  The $str argument can
  380. denote a relative or absolute URI.  If relative, then it will be
  381. absolutized using $base_uri as base. The $base_uri must be an absolute
  382. URI.
  383.  
  384. =item $uri = URI::file->new( $filename, [$os] )
  385.  
  386. This constructs a new I<file> URI from a file name.  See L<URI::file>.
  387.  
  388. =item $uri = URI::file->new_abs( $filename, [$os] )
  389.  
  390. This constructs a new absolute I<file> URI from a file name.  See
  391. L<URI::file>.
  392.  
  393. =item $uri = URI::file->cwd
  394.  
  395. This returns the current working directory as a I<file> URI.  See
  396. L<URI::file>.
  397.  
  398. =item $uri->clone
  399.  
  400. This method returns a copy of the $uri.
  401.  
  402. =back
  403.  
  404. =head1 COMMON METHODS
  405.  
  406. The methods described in this section are available for all C<URI>
  407. objects.
  408.  
  409. Methods that give access to components of a URI will always return the
  410. old value of the component.  The value returned will be C<undef> if the
  411. component was not present.  There is generally a difference between a
  412. component that is empty (represented as C<"">) and a component that is
  413. missing (represented as C<undef>).  If an accessor method is given an
  414. argument it will update the corresponding component in addition to
  415. returning the old value of the component.  Passing an undefined
  416. argument will remove the component (if possible).  The description of
  417. the various accessor methods will tell if the component is passed as
  418. an escaped or an unescaped string.  Components that can be futher
  419. divided into sub-parts are usually passed escaped, as unescaping might
  420. change its semantics.
  421.  
  422. The common methods available for all URI are:
  423.  
  424. =over 4
  425.  
  426. =item $uri->scheme( [$new_scheme] )
  427.  
  428. This method sets and returns the scheme part of the $uri.  If the $uri is
  429. relative, then $uri->scheme returns C<undef>.  If called with an
  430. argument, it will update the scheme of $uri, possibly changing the
  431. class of $uri, and return the old scheme value.  The method croaks
  432. if the new scheme name is illegal; scheme names must begin with a
  433. letter and must consist of only US-ASCII letters, numbers, and a few
  434. special marks: ".", "+", "-".  This restriction effectively means
  435. that scheme have to be passed unescaped.  Passing an undefined
  436. argument to the scheme method will make the URI relative (if possible).
  437.  
  438. Letter case does not matter for scheme names.  The string
  439. returned by $uri->scheme is always lowercase.  If you want the scheme
  440. just as it was written in the URI in its original case,
  441. you can use the $uri->_scheme method instead.
  442.  
  443. =item $uri->opaque( [$new_opaque] )
  444.  
  445. This method sets and returns the scheme specific part of the $uri
  446. (everything between the scheme and the fragment)
  447. as an escaped string.
  448.  
  449. =item $uri->path( [$new_path] )
  450.  
  451. This method sets and returns the same value as $uri->opaque unless the URI
  452. supports the generic syntax for hierarchical namespaces.
  453. In that case the generic method is overridden to set and return
  454. the part of the URI between the I<host name> and the I<fragment>.
  455.  
  456. =item $uri->fragment( [$new_frag] )
  457.  
  458. This method returns the fragment identifier of a URI reference
  459. as an escaped string.
  460.  
  461. =item $uri->as_string
  462.  
  463. This method returns a URI object to a plain string.  URI objects are
  464. also converted to plain strings automatically by overloading.  This
  465. means that $uri objects can be used as plain strings in most Perl
  466. constructs.
  467.  
  468. =item $uri->canonical
  469.  
  470. This method will return a normalized version of the URI.  The rules
  471. for normalization are scheme dependent.  It usually involves
  472. lowercasing of the scheme and the Internet host name components,
  473. removing the explicit port specification if it matches the default port,
  474. uppercasing all escape sequences, and unescaping octets that can be
  475. better represented as plain characters.
  476.  
  477. For efficiency reasons, if the $uri already was in normalized form,
  478. then a reference to it is returned instead of a copy.
  479.  
  480. =item $uri->eq( $other_uri )
  481.  
  482. =item URI::eq( $first_uri, $other_uri )
  483.  
  484. This method tests whether two URI references are equal.  URI references
  485. that normalize to the same string are considered equal.  The method
  486. can also be used as a plain function which can also test two string
  487. arguments.
  488.  
  489. If you need to test whether two C<URI> object references denote the
  490. same object, use the '==' operator.
  491.  
  492. =item $uri->abs( $base_uri )
  493.  
  494. This method returns an absolute URI reference.  If $uri already is
  495. absolute, then a reference to it is simply returned.  If the $uri
  496. is relative, then a new absolute URI is constructed by combining the
  497. $uri and the $base_uri, and returned.
  498.  
  499. =item $uri->rel( $base_uri )
  500.  
  501. This method returns a relative URI reference if it is possible to
  502. make one that denotes the same resource relative to $base_uri.
  503. If not, then $uri is simply returned.
  504.  
  505. =back
  506.  
  507. =head1 GENERIC METHODS
  508.  
  509. The following methods are available to schemes that use the
  510. common/generic syntax for hierarchical namespaces.  The description of
  511. schemes below will tell which one these are.  Unknown schemes are
  512. assumed to support the generic syntax, and therefore the following
  513. methods:
  514.  
  515. =over 4
  516.  
  517. =item $uri->authority( [$new_authority] )
  518.  
  519. This method sets and returns the escaped authority component
  520. of the $uri.
  521.  
  522. =item $uri->path( [$new_path] )
  523.  
  524. This method sets and returns the escaped path component of
  525. the $uri (the part between the host name and the query or fragment).
  526. The path will never be undefined, but it can be the empty string.
  527.  
  528. =item $uri->path_query( [$new_path_query] )
  529.  
  530. This method sets and returns the escaped path and query
  531. components as a single entity.  The path and the query are
  532. separated by a "?" character, but the query can itself contain "?".
  533.  
  534. =item $uri->path_segments( [$segment,...] )
  535.  
  536. This method sets and returns the path.  In scalar context it returns
  537. the same value as $uri->path.  In list context it will return the
  538. unescaped path segments that make up the path.  Path segments that
  539. have parameters are returned as an anonymous array.  The first element
  540. is the unescaped path segment proper.  Subsequent elements are escaped
  541. parameter strings.  Such an anonymous array uses overloading so it can
  542. be treated as a string too, but this string does not include the
  543. parameters.
  544.  
  545. =item $uri->query( [$new_query] )
  546.  
  547. This method sets and returns the escaped query component of
  548. the $uri.
  549.  
  550. =item $uri->query_form( [$key => $value,...] )
  551.  
  552. This method sets and returns query components that use the
  553. I<application/x-www-form-urlencoded> format.  Key/value pairs are
  554. separated by "&" and the key is separated from the value with a "="
  555. character.
  556.  
  557. =item $uri->query_keywords( [$keywords,...] )
  558.  
  559. This method sets and returns query components that use the
  560. keywords separated by "+" format.
  561.  
  562. =back
  563.  
  564. =head1 SERVER METHODS
  565.  
  566. Schemes where the I<authority> component denotes a Internet host will
  567. have the following methods available in addition to the generic
  568. methods.
  569.  
  570. =over 4
  571.  
  572. =item $uri->userinfo( [$new_userinfo] )
  573.  
  574. This method sets and returns the escaped userinfo part of the
  575. authority componenent.
  576.  
  577. For some schemes this will be a user name and a password separated by
  578. a colon.  This practice is not recommended. Embedding passwords in
  579. clear text (such as URI) has proven to be a security risk in almost
  580. every case where it has been used.
  581.  
  582. =item $uri->host( [$new_host] )
  583.  
  584. This method sets and returns the unescaped hostname.
  585.  
  586. If the $new_host string ends with a colon and a number, then this
  587. number will also set the port.
  588.  
  589. =item $uri->port( [ $new_port] )
  590.  
  591. This method sets and returns the port.  The port is simple integer
  592. that should be greater than 0.
  593.  
  594. If no explicit port is specified in the URI, then the default port of
  595. the URI scheme is returned. If you don't want the default port
  596. substituted, then you can use the $uri->_port method instead.
  597.  
  598. =item $uri->host_port( [ $new_host_port ] )
  599.  
  600. This method sets and returns the host and port as a single
  601. unit.  The returned value will include a port, even if it matches the
  602. default port.  The host part and the port part is separated with a
  603. colon; ":".
  604.  
  605. =item $uri->default_port
  606.  
  607. This method returns the default port of the URI scheme that $uri
  608. belongs to.  For I<http> this will be the number 80, for I<ftp> this
  609. will be the number 21, etc.  The default port for a scheme can not be
  610. changed.
  611.  
  612. =back
  613.  
  614. =head1 SCHEME SPECIFIC SUPPORT
  615.  
  616. The following URI schemes are specifically supported.  For C<URI>
  617. objects not belonging to one of these you can only use the common and
  618. generic methods.
  619.  
  620. =over 4
  621.  
  622. =item B<data>:
  623.  
  624. The I<data> URI scheme is specified in RFC 2397.  It allows inclusion
  625. of small data items as "immediate" data, as if it had been included
  626. externally.
  627.  
  628. C<URI> objects belonging to the data scheme support the common methods
  629. and two new methods to access their scheme specific components;
  630. $uri->media_type and $uri->data.  See L<URI::data> for details.
  631.  
  632. =item B<file>:
  633.  
  634. An old specification of the I<file> URI scheme is found in RFC 1738.
  635. A new RFC 2396 based specification in not available yet, but file URI
  636. references are in common use.
  637.  
  638. C<URI> objects belonging to the file scheme support the common and
  639. generic methods.  In addition they provide two methods to map file URI
  640. back to local file names; $uri->file and $uri->dir.  See L<URI::file>
  641. for details.
  642.  
  643. =item B<ftp>:
  644.  
  645. An old specification of the I<ftp> URI scheme is found in RFC 1738.  A
  646. new RFC 2396 based specification in not available yet, but ftp URI
  647. references are in common use.
  648.  
  649. C<URI> objects belonging to the ftp scheme support the common,
  650. generic and server methods.  In addition they provide two methods to
  651. access the userinfo sub-components: $uri->user and $uri->password.
  652.  
  653. =item B<gopher>:
  654.  
  655. The I<gopher> URI scheme is specified in
  656. <draft-murali-url-gopher-1996-12-04> and will hopefully be available
  657. as a RFC 2396 based specification.
  658.  
  659. C<URI> objects belonging to the gopher scheme support the common,
  660. generic and server methods. In addition they support some methods to
  661. access gopher specific path components: $uri->gopher_type,
  662. $uri->selector, $uri->search, $uri->string.
  663.  
  664. =item B<http>:
  665.  
  666. The I<http> URI scheme is specified in RFC 2616.
  667. The scheme is used to reference resources hosted by HTTP servers.
  668.  
  669. C<URI> objects belonging to the http scheme support the common,
  670. generic and server methods.
  671.  
  672. =item B<https>:
  673.  
  674. The I<https> URI scheme is a Netscape invention which is commonly
  675. implemented.  The scheme is used to reference HTTP servers through SSL
  676. connections.  Its syntax is the same as http, but the default
  677. port is different.
  678.  
  679. =item B<ldap>:
  680.  
  681. The I<ldap> URI scheme is specified in RFC 2255.  LDAP is the
  682. Lightweight Directory Access Protocol.  An ldap URI describes an LDAP
  683. search operation to perform to retrieve information from an LDAP
  684. directory.
  685.  
  686. C<URI> objects belonging to the ldap scheme support the common,
  687. generic and server methods as well as specific ldap methods; $uri->dn,
  688. $uri->attributes, $uri->scope, $uri->filter, $uri->extensions.  See
  689. L<URI::ldap> for details.
  690.  
  691. =item B<mailto>:
  692.  
  693. The I<mailto> URI scheme is specified in RFC 2368.  The scheme was
  694. originally used to designate the Internet mailing address of an
  695. individual or service.  It has (in RFC 2368) been extended to allow
  696. setting of other mail header fields and the message body.
  697.  
  698. C<URI> objects belonging to the mailto scheme support the common
  699. methods and the generic query methods.  In addition they support the
  700. following mailto specific methods: $uri->to, $uri->headers.
  701.  
  702. =item B<news>:
  703.  
  704. The I<news>, I<nntp> and I<snews> URI schemes are specified in
  705. <draft-gilman-news-url-01> and will hopefully be available as a RFC
  706. 2396 based specification soon.
  707.  
  708. C<URI> objects belonging to the news scheme support the common,
  709. generic and server methods.  In addition they provide some methods to
  710. access the path: $uri->group and $uri->message.
  711.  
  712. =item B<nntp>:
  713.  
  714. See I<news> scheme.
  715.  
  716. =item B<pop>:
  717.  
  718. The I<pop> URI scheme is specified in RFC 2384. The scheme is used to
  719. reference a POP3 mailbox.
  720.  
  721. C<URI> objects belonging to the pop scheme support the common, generic
  722. and server methods.  In addition they provide two methods to access the
  723. userinfo components: $uri->user and $uri->auth
  724.  
  725. =item B<rlogin>:
  726.  
  727. An old speficication of the I<rlogin> URI scheme is found in RFC
  728. 1738. C<URI> objects belonging to the rlogin scheme support the
  729. common, generic and server methods.
  730.  
  731. =item B<rtsp>:
  732.  
  733. The I<rtsp> URL specification can be found in section 3.2 of RFC 2326.
  734. C<URI> objects belonging to the rtsp scheme support the common,
  735. generic, and server methods, with the exception of userinfo and
  736. query-related sub-components.
  737.  
  738. =item B<rtspu>:
  739.  
  740. The I<rtspu> URI scheme is used to talk to RTSP servers over UDP
  741. instead of TCP.  The syntax is the same as rtsp.
  742.  
  743. =item B<rsync>:
  744.  
  745. Information about rsync is available from http://rsync.samba.org.
  746. C<URI> objects belonging to the rsync scheme support the common,
  747. generic and server methods.  In addition they provide methods to
  748. access the userinfo sub-components: $uri->user and $uri->password.
  749.  
  750. =item B<sip>:
  751.  
  752. The I<sip> URI specification is described in sections 19.1 and 25
  753. of RFC 3261.  C<URI> objects belonging to the sip scheme support the
  754. common, generic, and server methods with the exception of path related
  755. sub-components.  In addition, they provide two methods to get and set
  756. I<sip> parameters, $uri->params_form and $uri->params.
  757.  
  758. =item B<sips>:
  759.  
  760. See I<sip> scheme.  Its syntax is the same as sip, but the default
  761. port is different.
  762.  
  763. =item B<snews>:
  764.  
  765. See I<news> scheme.  Its syntax is the same as news, but the default
  766. port is different.
  767.  
  768. =item B<telnet>:
  769.  
  770. An old speficication of the I<telnet> URI scheme is found in RFC
  771. 1738. C<URI> objects belonging to the telnet scheme support the
  772. common, generic and server methods.
  773.  
  774. =item B<tn3270>:
  775.  
  776. There URIs are used like I<telnet> URIs but for connections to IBM
  777. mainframes.  C<URI> objects belonging to the tn3270 scheme support the
  778. common, generic and server methods.
  779.  
  780. =item B<ssh>:
  781.  
  782. Information about ssh is available at http://www.openssh.com/.
  783. C<URI> objects belonging to the ssh scheme support the common,
  784. generic and server methods. In addition they provide methods to
  785. access the userinfo sub-components: $uri->user and $uri->password.
  786.  
  787. =item B<urn>:
  788.  
  789. The syntax of Uniform Resource Names is specified in RFC 2141.  C<URI>
  790. objects belonging to the urn scheme provide the common methods and the
  791. methods: $uri->nid and $uri->nss that returns the Namespace Identifier
  792. and the Namespace Specific String respectively.
  793.  
  794. The Namespace Identifier basically works like the Scheme identifier of
  795. URIs, and further divides the URN namespace.  Namespace Identifier
  796. assignments are maintained at
  797. <http://www.iana.org/assignments/urn-namespaces>.
  798.  
  799. Letter case is not significant for the Namespace Identifier.  It is
  800. always returned in lower case by the $uri->nid method.  The $uri->_nid
  801. method can be used if you want it in its original case.
  802.  
  803. =item B<urn>:B<isbn>:
  804.  
  805. The C<urn:isbn:> namespace contains International Standard Book
  806. Numbers (ISBNs) and is described in RFC 3187.  C<URI> object belonging
  807. to this namespace has the following extra methods (if the
  808. Business::ISBN module is available); $uri->isbn,
  809. $uri->isbn_publisher_code, $uri->isbn_country_code, $uri->isbn_as_ean.
  810.  
  811. =item B<urn>:B<oid>:
  812.  
  813. The C<urn:oid:> namespace contains Object Identifiers (OIDs) and is
  814. described in RFC 3061.  An object identifier is sequences of digits
  815. separated by dots.  C<URI> object belonging to this namespace has an
  816. additional method called $uri->oid that can be used to get/set the oid
  817. value.  In list context oid numbers are returned as separate elements.
  818.  
  819. =back
  820.  
  821. =head1 CONFIGURATION VARIABLES
  822.  
  823. The following configuration variables influence how the class and its
  824. methods behave:
  825.  
  826. =over 4
  827.  
  828. =item $URI::ABS_ALLOW_RELATIVE_SCHEME
  829.  
  830. Some older parsers used to allow the scheme name to be present in the
  831. relative URL if it was the same as the base URL scheme.  RFC 2396 says
  832. that this should be avoided, but you can enable this old behaviour by
  833. setting the $URI::ABS_ALLOW_RELATIVE_SCHEME variable to a TRUE value.
  834. The difference is demonstrated by the following examples:
  835.  
  836.   URI->new("http:foo")->abs("http://host/a/b")
  837.       ==>  "http:foo"
  838.  
  839.   local $URI::ABS_ALLOW_RELATIVE_SCHEME = 1;
  840.   URI->new("http:foo")->abs("http://host/a/b")
  841.       ==>  "http:/host/a/foo"
  842.  
  843.  
  844. =item $URI::ABS_REMOTE_LEADING_DOTS
  845.  
  846. You can also have the abs() method ignore excess ".."
  847. segments in the relative URI by setting $URI::ABS_REMOTE_LEADING_DOTS
  848. to a TRUE value.  The difference is demonstrated by the following
  849. examples:
  850.  
  851.   URI->new("../../../foo")->abs("http://host/a/b")
  852.       ==> "http://host/../../foo"
  853.  
  854.   local $URI::ABS_REMOTE_LEADING_DOTS = 1;
  855.   URI->new("../../../foo")->abs("http://host/a/b")
  856.       ==> "http://host/foo"
  857.  
  858. =back
  859.  
  860. =head1 BUGS
  861.  
  862. Using regexp variables like $1 directly as argument to the URI methods
  863. do not work too well with current perl implementations.  I would argue
  864. that this is actually a bug in perl.  The workaround is to quote
  865. them. E.g.:
  866.  
  867.    /(...)/ || die;
  868.    $u->query("$1");
  869.  
  870. =head1 PARSING URIs WITH REGEXP
  871.  
  872. As an alternative to this module, the following (official) regular
  873. expression can be used to decode a URI:
  874.  
  875.   my($scheme, $authority, $path, $query, $fragment) =
  876.   $uri =~ m|(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?|;
  877.  
  878. The C<URI::Split> module provide the function uri_split() as a
  879. readable alternative.
  880.  
  881. =head1 SEE ALSO
  882.  
  883. L<URI::file>, L<URI::WithBase>, L<URI::Escape>, L<URI::Split>, L<URI::Heuristic>
  884.  
  885. RFC 2396: "Uniform Resource Identifiers (URI): Generic Syntax",
  886. Berners-Lee, Fielding, Masinter, August 1998.
  887.  
  888. http://www.iana.org/assignments/uri-schemes
  889.  
  890. http://www.iana.org/assignments/urn-namespaces
  891.  
  892. http://www.w3.org/Addressing/
  893.  
  894. =head1 COPYRIGHT
  895.  
  896. Copyright 1995-2003 Gisle Aas.
  897.  
  898. Copyright 1995 Martijn Koster.
  899.  
  900. This program is free software; you can redistribute it and/or modify
  901. it under the same terms as Perl itself.
  902.  
  903. =head1 AUTHORS / ACKNOWLEDGMENTS
  904.  
  905. This module is based on the C<URI::URL> module, which in turn was
  906. (distantly) based on the C<wwwurl.pl> code in the libwww-perl for
  907. perl4 developed by Roy Fielding, as part of the Arcadia project at the
  908. University of California, Irvine, with contributions from Brooks
  909. Cutter.
  910.  
  911. C<URI::URL> was developed by Gisle Aas, Tim Bunce, Roy Fielding and
  912. Martijn Koster with input from other people on the libwww-perl mailing
  913. list.
  914.  
  915. C<URI> and related subclasses was developed by Gisle Aas.
  916.  
  917. =cut
  918.